import imageDataApi from "@/views/js/api/imageDataApi";
import dirImageDataApi from "@/views/js/api/dirImageDataApi";
class Api {
  async getDirId(code) {
    let response = await dirImageDataApi.treeByCode({ code });
    if (response.success && response.content.length > 0) {
      return response.content[0].imageStoreDirId;
    }
  }
  //获取方案
  async getDesignList(getDataList, imageStoreDirId) {
    getDataList.imageStoreDirId = imageStoreDirId;
    let data = await imageDataApi.selectAuthPageByDirCode(getDataList);
    let designList = data.content.list.map((item) => {
      item.imageStoreInformation = JSON.parse(item.imageStoreInformation);
      return item;
    });
    return designList;
  }
  async selectAuthPageByDirCode(getDataList, imageStoreDirId) {
    // getDataList.imageStoreDirId = imageStoreDirId;
    // return new Promise((resolve, reject) => {
    //   agcim.net.axiosWraper
    //     .getData(
    //       "http://172.18.80.51/agcim-viewer-mgr-rest/io/imagestore/selectAuthByDirIdWithChildren",
    //       getDataList
    //     )
    //     .then(
    //       (response) => {
    //         if (response.success) {
    //           let designList = response.content.list.map((item) => {
    //             item.imageStoreInformation = JSON.parse(
    //               item.imageStoreInformation
    //             );
    //             return item;
    //           });
    //           resolve(designList);
    //         } else {
    //           reject(response);
    //         }
    //       },
    //       (error) => {
    //         reject(error);
    //       }
    //     );
    // });
  }
  async getModelPointsFromWFS(url, tableName) {
    return new Promise((resolve, reject) => {
      let queryHelper = new agcim.wfs.WFSQueryHelper(url);
      queryHelper._queryFeatrue(tableName).then((result) => {
        let pointsArray = [];
        if (result.features.length > 0) {
          result.features.forEach((feature, index) => {
            feature.properties.id = index;
            pointsArray.push(feature.geometry.coordinates)
          });
          resolve(pointsArray);
        } else {
          reject(null);
        }
      });
    })
  }
  async getWaterPolygonFromWFS(wfsUrl, tableName){
    return new Promise((resolve) => {
      let queryHelper = new agcim.wfs.WFSQueryHelper(wfsUrl);
      queryHelper._queryFeatrue(tableName).then((result) => {
          let feature = undefined;
          if (result.features.length > 0) {
              feature = result.features;
              resolve(feature);
          } else {
              reject(null);
          }
      });
    })
  }
}
export default new Api();
